/**
 * MinimaxNode.java
 * @author J.T. Gralka <gralkajt@washjeff.edu>, Topher Witt <wittcm19@uww.edu>
 * @version 06/15/11
 *
 * Stores information as a node value for the Minimax JHAVE visualization.
 */

package exe.minimax;

import java.util.ArrayList;

public class MinimaxNode {
	// iVars
	private MinimaxNode nextSibling; // references the node's next sibling for
										// MinimaxNodeList implementation
	private ArrayList<MinimaxNode> children; // references a MinimaxNodeList of
												// the current node's children
	private int value; // the current utility value of the node
	private int alpha, beta; // the current alpha or beta value of the node
	private boolean isMax; // is the node a MAX node?
	private boolean isLeaf; // is the node a leaf?
	private boolean isPruned; // is the node pruned?
	private boolean isUtilitySet; // is the utility value of the node set?
	private boolean isVisited; // has the node been explored?
	private boolean isPath; // node is contained in final path

	private int index;
	private boolean isCurrent;

	// Constructor
	public MinimaxNode(MinimaxNode nextSibling, boolean isMax, int value,
			boolean isLeaf, boolean isUtilitySet) {
		this.nextSibling = nextSibling;
		this.isMax = isMax;
		this.value = value;
		this.isLeaf = isLeaf;
		this.isUtilitySet = isUtilitySet;

		isVisited = false;
		isPruned = false;
		children = new ArrayList<MinimaxNode>();
		index = 0;
	}

	public MinimaxNode(boolean isMax, int value, boolean isUtilitySet) {
		this(null, isMax, value, false, isUtilitySet);
	}

	public MinimaxNode(int value) {
		this(true, value, true);
	}

	public MinimaxNode() {
		this(-1);
		isUtilitySet = false;
	}

	// Accessors
	public MinimaxNode getNext() {
		return nextSibling;
	}

	public int getValue() {
		return value;
	}
	
	public boolean isPath() {
		return isPath;
	}

	public boolean isCurrent() {
		return isCurrent;
	}

	public int getAlpha() {
		return alpha;
	}

	public int getBeta() {
		return beta;
	}

	public boolean isMax() {
		return isMax;
	}

	public boolean isPruned() {
		return isPruned;
	}

	public ArrayList<MinimaxNode> getChildren() {
		return children;
	}

	public boolean isLeaf() {
		return isLeaf;
	}

	public boolean isUtilitySet() {
		return isUtilitySet;
	}

	public boolean isVisited() {
		return isVisited;
	}

	public int getIndex() {
		return index;
	}

	// Mutators
	public void setNext(MinimaxNode nextSibling) {
		this.nextSibling = nextSibling;
	}

	public void setValue(int value) {
		this.value = value;
		isUtilitySet = true;
	}

	public void setAlpha(int alpha) {
		this.alpha = alpha;
	}

	public void setBeta(int beta) {
		this.beta = beta;
	}

	public void setIsPath(boolean isPath){
		this.isPath = isPath;
	}
	
	public void setIsMax(boolean isMax) {
		this.isMax = isMax;
	}

	public void setIsPruned(boolean isPruned) {
		this.isPruned = isPruned;
	}

	public void setChildren(ArrayList<MinimaxNode> children) {
		this.children = children;
	}

	public void setIsLeaf(boolean isLeaf) {
		this.isLeaf = isLeaf;
		isUtilitySet = true;
	}

	public void setIsVisited(boolean isVisited) {
		this.isVisited = isVisited;
	}

	public void setIsCurrent(boolean isCurrent) {
		this.isCurrent = isCurrent;
	}

	public void setIndex(int index) {
		this.index = index;
	}

	// Helper methods
	public String toString() {
		String str = (isMax ? "MAX" : "MIN") + " node";
		if (!isUtilitySet)
			return str += " which is unvisited";
		return str += " with a value of " + value;
	}
}
